﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VOD.Models;

namespace VOD.Controllers.Filters
{
    public class SiteCounterFilter : FilterAttribute, IResultFilter
    {
        VODEntities db = new VODEntities();
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
            try
            {
                var count = new SiteCount()
                {
                    IP_Addr = filterContext.HttpContext.Request.UserHostAddress,
                    AddDate = DateTime.Now
                };
                db.SiteCounts.Add(count);
                db.SaveChanges();
            }
            catch { }
        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
        }
    }
}